<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class JoinmeController extends Controller
{
    public function add(Request $request)
    {
        $data = $request -> except('_token');
        $time = Date('Y-m-d H:i:s');
        $data['created_at'] = $time;
        $res = DB::table('joinme') -> insertGetID($data);
        if($res)
        {
             return redirect('home/index') -> with(['info' => '提交成功,届时我们会有工作人员与您取得联系']);
        }else
        {
             return back() -> with(['info' => '提交失败,请您重新输入']);
        }
    }
    public function index(Request $request)
    {
         $num = $request -> input('num',10);
         $keywords = $request -> input('keywords','');
         $data = DB::table('joinme')
               -> where('name','like','%'.$keywords.'%')
               -> paginate($num);
         // dd($data);
         return view('admin.joinme.index',['data'=>$data,'title'=>'加盟商信息','request' => $request -> all()]);
    }
    public function delete($id)
    {
         $res = DB::table('joinme') -> where('id',$id) -> delete();
         if($res)
         {
               return redirect('admin/joinme/index') -> with(['info' => '删除成功']);
         }else
         {
               return back() -> with(['info' => '删除失败']);
         }
    }
}
